<!--导航栏-->
<script setup>
import { useRouter } from 'vue-router'
import {computed, onMounted, ref} from "vue";
import {getRoleId} from "../api/login.js";

const router = useRouter();

const roleId = ref(null);

// 导航栏函数
const handleSelect = (index) => {
  switch (index) {
    // 首页
    case "1":
      router.push('/home')
      break;
    // 测试2——教师
    case "2":
      router.push('/test2')
      break;
    case "2-1-1":
      router.push('/test2/statisticalAndAnalysis/OneStudent')
      break;
    case "2-1-2":
      router.push('/test2/statisticalAndAnalysis/AllStudent')
      break;
    case "2-2-1":
      router.push('/test2/TemplateList')
      break;
    case "2-2-2":
      router.push('/test2/MetadataList')
      break;
    case "2-2-3":
      router.push('/test2/ExtractContentList')
      break;
      case "2-2-4":
      router.push('/test2/ScoreManage')
      break;
    // 测试3——学生
    case "3":
      router.push('/test3')
      break;
    // 测试4——学院负责人
    case "4":
      router.push('/test4')
      break;
    // 个人中心
    case "5":
      router.push('/person')
      break;
    /*
      管理员端
     */
    // 数据管理——模板管理
    case "1-4-1":
      router.push('/templateManagement')
      break;
    // 数据管理——论文元数据管理
    case "1-4-2":
      router.push('/splitPaperMetadataManagement')
      break;
    // 数据管理——抽取正文内容管理
    case "1-4-3":
      router.push('/extractContentManagement')
      break;
    // 数据管理——评分管理
    case "1-4-4":
      router.push('/factorScoreManagement')
      break;
    // 模板数据管理
    case "1-4-5":
      router.push('/TemplateTypeManagement')
      break;
    // 抽检表查看
    case "1-4-6":
      router.push('/DictElementTable')
      break;
    case "1-6":
      router.push('/statisticAnalysis')
      break;
    // 预测
    case "1-7":
      router.push('/predictionByKeywords')
      break;
    default:
      break;
  }
}

// 获取角色 ID
const fetchRoleId = async () => {
  try {
    const response = await getRoleId();
    roleId.value = response.data;  // 保存角色 ID
  } catch (error) {
    console.error('获取角色 ID 失败:', error);
  }
};

// 角色判断
// 学院负责人
const isFacultyAdmin = computed(() => roleId.value === 1);
// 指导老师
const isTeacher = computed(() => roleId.value === 2);
// 学生
const isStudent = computed(() => roleId.value === 3);

onMounted(() => {
  // 获取角色 ID
  fetchRoleId();
});
</script>

<template>
  <div class="common-layout">
<!--    学院负责人FacultyAdmin-->
    <template v-if="isFacultyAdmin">
      <el-container>
        <el-header class="custom-header">
          <div class="header-wave"></div>
          <div class="header-content">
            <div class="header-logo">
              <i class="el-icon-document"></i>
            </div>
            <div class="header-title">档案柜系统</div>
            <div class="header-right">
<!--              学院负责人端个人中心-->
              <div class="personal-center" @click="handleSelect('5')">
                <i class="el-icon-user"></i>
                <span>个人中心</span>
              </div>
            </div>
          </div>
        </el-header>
        <el-container class="custom-content">
          <el-aside class="custom-aside" width="240px">
            <div class="aside-user">
              <div class="user-avatar">A</div>
              <div class="user-info">
                <div class="user-role">学院负责人</div>
                <div class="user-status">在线</div>
              </div>
            </div>

            <el-menu class="custom-menu" @select="handleSelect">
<!--              学院负责人端首页-->
              <el-menu-item index="1">
                <i class="menu-icon el-icon-s-home"></i>
                <span>首页</span>
              </el-menu-item>
<!--              学院负责人端数据字典管理-->
              <el-sub-menu index="">
                <template #title>
                  <i class="menu-icon el-icon-s-tools"></i>
                  <span>数据字典管理</span>
                </template>
                <el-menu-item index="-1">专业管理</el-menu-item>
                <el-menu-item index="1-4-5">模版类型管理</el-menu-item>
                <el-menu-item index="1-4-6">抽检表查看</el-menu-item>
              </el-sub-menu>
<!--              学院负责人端用户管理-->
              <el-sub-menu index="">
                <template #title>
                  <i class="menu-icon el-icon-s-tools"></i>
                  <span>用户管理</span>
                </template>
                <el-menu-item index="-1">教师管理</el-menu-item>
                <el-menu-item index="-2">学生管理</el-menu-item>
              </el-sub-menu>
<!--              学院负责人端数据管理-->
              <el-sub-menu index="1-4">
                <template #title>
                  <i class="menu-icon el-icon-s-tools"></i>
                  <span>数据管理</span>
                </template>
                <el-menu-item index="1-4-1">模板管理</el-menu-item>
                <el-menu-item index="1-4-2">论文元数据管理</el-menu-item>
                <el-menu-item index="1-4-3">抽取内容管理</el-menu-item>
                <el-menu-item index="1-4-4">评分管理</el-menu-item>
              </el-sub-menu>
<!--              学院负责人端往届论文批量上传-->
              <el-menu-item index="4">
                <i class="menu-icon el-icon-upload"></i>
                <span>往届论文批量上传</span>
              </el-menu-item>
<!--              学院负责人端统计分析-->
              <el-menu-item index="1-6">
                <i class="menu-icon el-icon-upload"></i>
                <span>统计分析</span>
              </el-menu-item>
<!--              学院负责人端预测-->
              <el-menu-item index="1-7">
                <i class="menu-icon el-icon-upload"></i>
                <span>预测分析</span>
              </el-menu-item>
            </el-menu>
          </el-aside>

          <el-main class="custom-main">
            <router-view></router-view>
          </el-main>
        </el-container>
      </el-container>
    </template>
<!--    指导老师Teacher-->
    <template v-else-if="isTeacher">
      <el-container class="user-layout">
        <div class="user-header">
          <div class="wave-bg"></div>
          <div class="header-container">
            <div class="header-logo">
              <i class="el-icon-collection"></i>
            </div>
            <div class="header-title">档案柜系统</div>
            <div class="header-right">
<!--              教师端个人中心-->
              <div class="personal-center" @click="handleSelect('5')">
                <i class="el-icon-user"></i>
                <span>个人中心</span>
              </div>
            </div>
          </div>
        </div>

        <div class="nav-wrapper">
          <el-menu
              class="top-menu"
              mode="horizontal"
              :ellipsis="false"
              @select="handleSelect"
              background-color="transparent"
          >
<!--            教师端首页-->
            <el-menu-item index="1">
              <i class="menu-icon el-icon-s-home"></i>
              <span>首页</span>
            </el-menu-item>
<!--            教师端统计分析-->
            <el-sub-menu index="">
              <template #title>
                <i class="menu-icon el-icon-s-tools"></i>
                <span>统计分析</span>
              </template>
              <el-menu-item index="2-1-1">学生个人统计</el-menu-item>
              <el-menu-item index="2-1-2">学生整体统计</el-menu-item>
            </el-sub-menu>
<!--            教师端数据查看-->
            <el-sub-menu index="2-2-1">
              <template #title>
                <i class="menu-icon el-icon-s-tools"></i>
                <span>数据查看</span>
              </template>
              <el-menu-item index="2-2-1">模板查看</el-menu-item>
              <el-menu-item index="2-2-2">论文元数据查看</el-menu-item>
              <el-menu-item index="2-2-3">抽取内容查看</el-menu-item>
              <el-menu-item index="2-2-4">评分查看</el-menu-item>
            </el-sub-menu>
<!--            教师端预测分析-->
            <el-menu-item index="1-12">
              <i class="menu-icon el-icon-upload"></i>
              <span>预测分析</span>
            </el-menu-item>
          </el-menu>
        </div>

        <el-main class="user-main">
          <router-view></router-view>
        </el-main>
      </el-container>
    </template>
<!--    学生Student-->
    <template v-else-if="isStudent">
      <el-container class="user-layout">
        <div class="user-header">
          <div class="wave-bg"></div>
          <div class="header-container">
            <div class="header-logo">
              <i class="el-icon-collection"></i>
            </div>
            <div class="header-title">档案柜系统</div>
            <div class="header-right">
<!--              学生端个人中心-->
              <div class="personal-center" @click="handleSelect('5')">
                <i class="el-icon-user"></i>
                <span>个人中心</span>
              </div>
            </div>
          </div>
        </div>

        <div class="nav-wrapper">
          <el-menu
              class="top-menu"
              mode="horizontal"
              :ellipsis="false"
              @select="handleSelect"
              background-color="transparent"
          >
<!--            学生端首页-->
            <el-menu-item index="1">
              <i class="menu-icon el-icon-s-home"></i>
              <span>首页</span>
            </el-menu-item>
<!--            学生端上传论文-->
            <el-menu-item index="3">
              <i class="menu-icon el-icon-upload"></i>
              <span>上传论文</span>
            </el-menu-item>
<!--            学生端论文查看-->
            <el-menu-item index="">
              <i class="menu-icon el-icon-upload"></i>
              <span>论文查看</span>
            </el-menu-item>
          </el-menu>
        </div>

        <el-main class="user-main">
          <router-view></router-view>
        </el-main>
      </el-container>
    </template>
  </div>
</template>

<style scoped>
.common-layout {
  height: 100vh;
  width: 100vw;
  margin: 0;
  padding: 0;
  overflow: hidden;
  font-family: "Microsoft YaHei", "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", Arial, sans-serif;
}

.menu-icon {
  margin-right: 10px;
  font-size: 20px;
}

.custom-header {
  height: 75px;
  background: #4fc6f2;
  color: white;
  display: flex;
  align-items: center;
  position: relative;
  overflow: hidden;
  z-index: 10;
}

.header-wave {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #4fc6f2 0%, #3a7bd5 100%);
  opacity: 0.95;
}

.header-wave::after {
  content: "";
  position: absolute;
  bottom: -10px;
  left: 0;
  width: 100%;
  height: 20px;
  background-size: cover;
  background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 320"><path fill="white" fill-opacity="1" d="M0,160L48,154.7C96,149,192,139,288,138.7C384,139,480,149,576,149.3C672,149,768,139,864,133.3C960,128,1056,128,1152,144C1248,160,1344,192,1392,208L1440,224L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z"></path></svg>') no-repeat;
}

.header-content {
  display: flex;
  align-items: center;
  position: relative;
  z-index: 1;
  padding: 0 25px;
  width: 100%;
}

.header-logo {
  font-size: 26px;
  margin-right: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(5px);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease;
}

.header-logo:hover {
  transform: rotate(15deg);
}

.header-title {
  font-size: 28px;
  font-weight: bold;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  letter-spacing: 1px;
  white-space: nowrap;
}

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
}

.personal-center {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 8px 15px;
  border-radius: 20px;
  background-color: rgba(255, 255, 255, 0.2);
  transition: all 0.3s ease;
}

.personal-center:hover {
  background-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
}

.personal-center i {
  margin-right: 5px;
  font-size: 18px;
}

.personal-center span {
  font-weight: 600;
  font-size: 16px;
}

.custom-content {
  height: calc(100vh - 70px);
  display: flex;
  background-color: #f5f7fa;
}

.custom-aside {
  background: #ffffff;
  padding: 0;
  transition: all 0.3s;
  box-shadow: 0 0 25px rgba(0, 0, 0, 0.05);
  position: relative;
  z-index: 5;
}

.aside-user {
  padding: 25px 20px;
  display: flex;
  align-items: center;
  background: linear-gradient(135deg, rgba(58, 194, 159, 0.08) 0%, rgba(58, 123, 213, 0.08) 100%);
  border-bottom: 1px solid rgba(240, 240, 240, 0.6);
  margin-bottom: 15px;
}

.user-avatar {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4fc6f2 0%, #3a7bd5 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: bold;
  margin-right: 12px;
  box-shadow: 0 4px 10px rgba(58, 189, 194, 0.3);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.user-avatar:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 12px rgba(58, 189, 194, 0.3);
}

.user-info {
  display: flex;
  flex-direction: column;
}

.user-role {
  font-size: 17px;
  font-weight: 600;
  color: #434343;
  margin-bottom: 4px;
}

.user-status {
  font-size: 14px;
  color: #4fc6f2;
  display: flex;
  align-items: center;
  font-weight: 500;
}

.user-status::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  background-color: #4fc6f2;
  border-radius: 50%;
  margin-right: 5px;
}

.custom-menu {
  border-right: none;
  padding: 5px 15px;
}

.custom-menu :deep(.el-menu-item),
.custom-menu :deep(.el-sub-menu__title) {
  height: 56px;
  line-height: 56px;
  margin: 8px 0;
  border-radius: 12px;
  transition: all 0.3s ease;
  font-size: 17px;
  font-weight: 600;
  color: #434343;
}

.custom-menu :deep(.el-sub-menu .el-menu-item) {
  font-size: 16px;
  font-weight: 600;
  height: 50px;
  line-height: 50px;
  color: #434343;
}

.custom-menu :deep(.el-menu-item:hover),
.custom-menu :deep(.el-sub-menu__title:hover) {
  background-color: rgba(58, 194, 159, 0.08);
  transform: translateX(5px);
  color: #4fc6f2;
}

.custom-menu :deep(.el-menu-item.is-active) {
  background: linear-gradient(90deg, #4fc6f2, #3a7bd5);
  color: white !important;
  box-shadow: 0 5px 15px rgba(58, 189, 194, 0.3);
}

.custom-main {
  background: #f5f7fa;
  padding: 25px;
  position: relative;
  z-index: 1;
}

/*用户*/
.user-layout {
  height: 100vh;
  width: 100vw;
  display: flex;
  flex-direction: column;
}

.user-header {
  position: relative;
  height: 75px;
  overflow: hidden;
  color: white;
}

.wave-bg {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #4fc6f2 0%, #3a7bd5 100%);
}

.wave-bg::after {
  content: "";
  position: absolute;
  bottom: -5px;
  left: 0;
  width: 100%;
  height: 40px;
  background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 320"><path fill="white" fill-opacity="1" d="M0,64L48,80C96,96,192,128,288,128C384,128,480,96,576,106.7C672,117,768,171,864,176C960,181,1056,139,1152,133.3C1248,128,1344,160,1392,176L1440,192L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z"></path></svg>');
  background-size: cover;
  background-repeat: no-repeat;
}

.header-container {
  position: relative;
  max-width: 1400px;
  height: 100%;
  margin: 0 auto;
  padding: 0 30px;
  display: flex;
  align-items: center;
  z-index: 2;
}

.header-container .header-right {
  margin-left: auto;
}

.nav-wrapper {
  background: white;
  position: relative;
  z-index: 5;
}

.top-menu {
  max-width: 1400px;
  height: 68px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  border-bottom: none;
}

.menu-item-content {
  display: flex;
  align-items: center;
  height: 100%;
}

.with-dropdown {
  padding-right: 15px;
}

/* Enhanced dropdown menu styles */
.visualization-dropdown :deep(.el-menu) {
  border-radius: 16px;
  padding: 10px;
  min-width: 200px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  border: none;
  background-color: #ffffff;
  transform-origin: top center;
  animation: dropdown-fade-in 0.25s ease;
}

@keyframes dropdown-fade-in {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.visualization-dropdown :deep(.el-menu-item) {
  height: 50px !important;
  line-height: 50px !important;
  margin: 4px 0;
  border-radius: 10px;
  font-size: 16px !important;
  font-weight: 500 !important;
  color: #444 !important;
  padding: 0 15px !important;
  transition: all 0.2s ease-out;
  position: relative;
}

.visualization-dropdown :deep(.el-menu-item:hover) {
  background-color: rgba(58, 189, 194, 0.3);
  color: #4fc6f2 !important;
  padding-left: 20px !important;
}

.visualization-dropdown :deep(.el-menu-item.is-active) {
  color: #4fc6f2 !important;
  font-weight: 600 !important;
  background-color: rgba(58, 194, 159, 0.12);
}

.visualization-dropdown :deep(.el-menu-item)::before {
  content: '';
  position: absolute;
  width: 0;
  height: 0;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  border-radius: 50%;
  background: #4fc6f2;
  transition: all 0.2s ease-out;
}

.visualization-dropdown :deep(.el-menu-item:hover)::before {
  width: 6px;
  height: 6px;
}

.visualization-dropdown :deep(.el-menu-item.is-active)::before {
  width: 8px;
  height: 8px;
}

.top-menu :deep(.el-sub-menu__icon-arrow) {
  margin-top: -4px;
  right: -8px;
  font-size: 14px;
  font-weight: bold;
  transition: transform 0.3s;
}

.top-menu :deep(.el-sub-menu.is-active) .el-sub-menu__icon-arrow {
  transform: rotate(180deg);
}

.flex-grow {
  flex-grow: 1;
}

.top-menu :deep(.el-menu-item),
.top-menu :deep(.el-sub-menu__title) {
  height: 68px;
  line-height: 68px;
  font-size: 17px;
  font-weight: 600;
  transition: all 0.3s ease;
  padding: 0 22px;
  position: relative;
  color: #434343;
}

.top-menu :deep(.el-sub-menu .el-menu-item) {
  height: 50px;
  line-height: 50px;
  font-size: 16px;
  font-weight: 600;
  padding: 0 22px;
}

.top-menu :deep(.el-menu-item:hover),
.top-menu :deep(.el-sub-menu__title:hover) {
  color: #4fc6f2;
}

.top-menu :deep(.el-menu-item.is-active) {
  color: #4fc6f2;
  font-weight: 700;
}

.top-menu :deep(.el-menu-item.is-active)::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 22px;
  right: 22px;
  height: 3px;
  background: linear-gradient(90deg, #4fc6f2, #3a7bd5);
  border-radius: 3px 3px 0 0;
  box-shadow: 0 0 8px rgba(58, 189, 194, 0.3);
}

.top-menu :deep(.el-menu-item):hover::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: 22px;
  right: 22px;
  height: 3px;
  background: linear-gradient(90deg, #4fc6f2 0%, #3a7bd5 100%);
  opacity: 0.3;
  border-radius: 3px 3px 0 0;
  transition: opacity 0.3s ease;
}

.user-main {
  background: #f5f7fa;
  padding: 30px;
  flex: 1;
  overflow-y: auto;
  position: relative;
}

.custom-main::-webkit-scrollbar,
.user-main::-webkit-scrollbar {
  width: 8px;
}

.custom-main::-webkit-scrollbar-track,
.user-main::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

.custom-main::-webkit-scrollbar-thumb,
.user-main::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 4px;
}

.custom-main::-webkit-scrollbar-thumb:hover,
.user-main::-webkit-scrollbar-thumb:hover {
  background: #4fc6f2;
}

@media (max-width: 1200px) {
  .header-title {
    font-size: 26px;
  }

  .top-menu :deep(.el-menu-item),
  .top-menu :deep(.el-sub-menu__title) {
    padding: 0 18px;
    font-size: 16px;
  }
}

@media (max-width: 992px) {
  .header-title {
    font-size: 24px;
  }

  .user-header {
    height: 100px;
  }

  .top-menu :deep(.el-menu-item),
  .top-menu :deep(.el-sub-menu__title) {
    padding: 0 15px;
    font-size: 16px;
  }

  .personal-center {
    padding: 6px 12px;
  }

  .personal-center span {
    font-size: 14px;
  }
}
</style>